package ten;

public class DeadLock {
    public static void main(String[] args) {
        new MakeUp(1, "张柏芝").start();
        new MakeUp(0, "王菲").start();
    }
}

class Lipstick{

}

class Mirror{

}

class MakeUp extends Thread{
    static Lipstick lipstick = new Lipstick();
    static Mirror mirror = new Mirror();
    int choice;
    String girl;

    public MakeUp(int choice, String girl){
        this.choice = choice;
        this.girl = girl;
    }
    @Override
    public void run() {
        makeup();
    }

    private void makeup() {
        if(choice == 0){
            synchronized (lipstick){
                System.out.println(this.girl+"涂口红");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
//                synchronized (mirror){
//                    System.out.println(this.girl + "照镜子");
//                }
            }
            synchronized (mirror){
                System.out.println(this.girl + "照镜子");
            }
        }else{
            synchronized (mirror){
                System.out.println(this.girl+"照镜子");
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
//                synchronized (lipstick){
//                    System.out.println(this.girl + "涂口红");
//                }
            }
            synchronized (lipstick){
                System.out.println(this.girl + "涂口红");
            }
        }
    }
}